import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    token: undefined,
    userinfo: undefined
  },
  getters: {
    token: (state) => state.token,
    islogin: (state) => !!state.token,
    userinfo: (state) => state.userinfo || {}
  },
  mutations: {
    login: (state, data) => {
      state.token = data.token;
      state.userinfo = data.userinfo;
    },
    logout: (state) => {
      state.token = undefined;
      state.userinfo = undefined;
    }
  }
});
